package com.twenty.seven.demo.demo.service.impl;

import com.twenty.seven.common.enums.StatusCode;
import com.twenty.seven.common.exception.CustomException;
import com.twenty.seven.demo.demo.jpa.UserJpa;
import com.twenty.seven.demo.demo.service.UserService;
import com.twenty.seven.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 001
 * @Date 2020/1/8 16:31
 * @TODO
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserJpa userJpa;
    @Override
    public User save(User user) {
        return userJpa.save(user);
    }

    @Override
    public User queryUserById(long id) throws CustomException {
        if(id <= 0){
            throw new CustomException(StatusCode.paramError.getCode(),StatusCode.paramError.getName());
        }
        return userJpa.findUserById(id);
    }
}
